package com.shen.jcbf.thread;

public class ThreadTest01 extends Thread {

	private int baoZi = 1;

	private String threadName;

	public ThreadTest01(String threadName) {
		super();
		this.threadName = threadName;
	}

	@Override
    public void run() {
        while(baoZi<=100){
        	synchronized(this){
        		if(baoZi>100) {
                    return;
                }
	            System.out.println(threadName+Thread.currentThread().getName()+" 吃"+baoZi+"第个包子");
	            baoZi++;
	            try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
        	}
        }
    }

	public static void main(String[] args) {
		ThreadTest01 t1 = new ThreadTest01("线程一");
		ThreadTest01 t2 = new ThreadTest01("线程二");
		ThreadTest01 t3 = new ThreadTest01("线程三");
		Thread t11 = new Thread(t1);
		Thread t12 = new Thread(t2);
		Thread t13 = new Thread(t3);
		t11.start();
		t12.start();
		t13.start();
	}

}
